package cn.itcast.test;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

public class ServletTest1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        接收用户信息
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String password1 = req.getParameter("password1");
//        判断密码是否一致

        if (!password.equals(password1)){
            PrintWriter pw = resp.getWriter();
            pw.println("Password mistake");
            pw.close();
        }else {
//        将信息写入文档
        BufferedWriter bw = new BufferedWriter(new FileWriter("d:\\user.txt",true));
        bw.write(username + "," + password);
        bw.newLine();
        bw.close();
//        响应客户端
            PrintWriter pw = resp.getWriter();
        pw.println("Make Success");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
